package zhuoyue.com.yanjiaohui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import ezy.ui.view.BannerView;
import zhuoyue.com.yanjiaohui.R;
import zhuoyue.com.yanjiaohui.acticity.FinancialStatementActivity;
import zhuoyue.com.yanjiaohui.acticity.ProjectManagerActivity;
import zhuoyue.com.yanjiaohui.acticity.ShopActivity;
import zhuoyue.com.yanjiaohui.acticity.ShopHoursActivity;
import zhuoyue.com.yanjiaohui.adapter.GridAdapter;
import zhuoyue.com.yanjiaohui.entity.BannerItem;
import zhuoyue.com.yanjiaohui.util.BannerViewFactory;


/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends Fragment implements AdapterView.OnItemClickListener {


    private BannerView mBannerView;

    public HomeFragment() {
        // Required empty public constructor
    }

    private GridView mGridView;
    private GridAdapter mAdapter;

    //下面是gridview数据
    private String mTitle[]=new String[]{
            "项目管理","自助上单","口碑管理","验证历史",
            "财务结款","经营数据","门店管理","自助推广",
            "推广通","借钱","商家论坛","同城活动"};

    private Integer mImage[]={
            R.drawable.icons_16,R.drawable.icons_19,
            R.drawable.icons_22,R.drawable.icons_25,
            R.drawable.icons_31,R.drawable.icons_32,
            R.drawable.icons_33,R.drawable.icons_34,
            R.drawable.icons_39,R.drawable.icons_40,
            R.drawable.icons_41,R.drawable.icons_42,
    };
    //下面是轮播数据
    private static  String [] mBannerTitle=new String[]{
            "每周7件Tee不重样",
            "俏皮又知性 适合上班族的漂亮衬衫",
            "名侦探柯南",
            "境界之轮回",
            "我的英雄学院",
            "全职猎人",
    };
    public static String[] urls = new String[]{//750x500
            "https://s2.mogucdn.com/mlcdn/c45406/170422_678did070ec6le09de3g15c1l7l36_750x500.jpg",
            "https://s2.mogucdn.com/mlcdn/c45406/170420_1hcbb7h5b58ihilkdec43bd6c2ll6_750x500.jpg",
            "http://s18.mogucdn.com/p2/170122/upload_66g1g3h491bj9kfb6ggd3i1j4c7be_750x500.jpg",
            "http://s18.mogucdn.com/p2/170204/upload_657jk682b5071bi611d9ka6c3j232_750x500.jpg",
            "http://s16.mogucdn.com/p2/170204/upload_56631h6616g4e2e45hc6hf6b7g08f_750x500.jpg",
            "http://s16.mogucdn.com/p2/170206/upload_1759d25k9a3djeb125a5bcg0c43eg_750x500.jpg"
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        //gridView
        mGridView = (GridView) view.findViewById(R.id.home_grid_view);
        mAdapter = new GridAdapter(getContext(), mTitle, mImage);
        mGridView.setAdapter(mAdapter);
        mGridView.setOnItemClickListener(this);
        //Banner
        List<BannerItem> list = new ArrayList<>();
        for (int i = 0; i < urls.length; i++) {
           BannerItem item=new BannerItem();
            item.image = urls[i];
            item.title = mBannerTitle[i];
            list.add(item);
        }

        mBannerView = (BannerView) view.findViewById(R.id.home_banner);
        mBannerView.setViewFactory(new BannerViewFactory());
        mBannerView.setDataList(list);
        mBannerView.start();

        return view;

    }

    //这个是gridview的点击事件。
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0:
                startActivity(new Intent(getContext(), ProjectManagerActivity.class));
                break;
            case 1:
                startActivity(new Intent(getContext(), ShopHoursActivity.class));
                break;
            case 2:
                startActivity(new Intent(getContext(), ProjectManagerActivity.class));
                break;
            case 3:
                //startActivity(new Intent(getContext(), ShopHoursActivity.class));
                break;
            case 4:
                startActivity(new Intent(getContext(), FinancialStatementActivity.class));
                break;

            case 5:
                startActivity(new Intent(getContext(), ShopHoursActivity.class));
                break;
            case 6:
                startActivity(new Intent(getContext(), ShopActivity.class));
                break;


        }

    }

    //这个是轮播图的点击事件


}
